<template>
  <el-select
    clearable
    filterable
    placeholder="-运动项目-"
    class="ele-block"
    :value="value"
    @change="chageProjectId">
    <el-option v-for="item in option" :key="item.id" :label="item.name" :value="item.id"/>
  </el-select>
</template>

<script>
export default {
  props: {
    value: {
      type: Number,
      default:8
    },
  },
  data: function () {
    return {
      option: [],
      loading: false,
    };
  },
  mounted() {
    this.loading = true
    this.$http.get('/project/getProjectList').then(res => {
        if (res.data.code === 0) {
          this.option = res.data.data;
          // this.value = this.option && this.option.length > 0 ? this.option[0].id : ''
          this.$emit("chageProject",this.option && this.option.length > 0 ? this.option[0].id : '')
        } else {
          this.$message.error(res.data.msg);
        }
      this.loading = false
    }).catch(e => {
      this.loading = false
      this.$message.error(e.message);
    });
  },
  methods: {
    chageProjectId(val) {
      this.$emit('chageProjectId', val);
    }
  },
};
</script>
